package com.java2_24;

import java.util.Objects;

public class Test implements Cloneable{
    private String name;
    private int age;
    private int[] arr = {1,2,3,4,5};

    public Test(){

    }
    public Test(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int[] getArr() {
        return arr;
    }

    public void setArr(int[] arr) {
        this.arr = arr;
    }

    @Override
    public String toString() {
        return name + " " + age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Test test = (Test) o;
        return age == test.age && Objects.equals(name, test.name);
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        int[] arr1 = this.arr;
        //换地址
        int[] arr2 = new int[arr1.length];
        for (int i = 0; i < arr1.length; i++) {
            arr2[i] = arr1[i];
        }
        Test clone = (Test) super.clone();
        clone.arr = arr2;
        return clone;

    }
}
